﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DLL;
using Module;

namespace BLL
{
    public class BPost
    {
        #region 字段

        private DPost APP = new DPost();//数据操作对象
        private static BPost instance;

        #endregion

        #region 公共接口
        /// <summary>
        /// 取得
        /// </summary>
        /// <returns>BPost对象</returns>
        public static BPost getInstance()
        {
            if (instance == null)
            {
                instance = new BPost();
            }
            return instance;
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="postInfo"></param>
        /// <returns></returns>
        public bool Insert(PostInfo postInfo)
        {
            if (postInfo == null || postInfo.PostId == 0)
                return false;
            return APP.Insert(postInfo);

        }


        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="postInfo"></param>
        /// <returns></returns>
        public bool Update(PostInfo postInfo)
        {
              if (postInfo == null || postInfo.PostId == 0)
                return false;
              return APP.Update(postInfo);
        }
        /// <summary>
        /// 根据文章Id删除所有回复
        /// </summary>
        /// <param name="paperId"></param>
        /// <returns></returns>
        public int DeleteByPagerId(long paperId)
        {
            if (paperId == 0 || paperId.ToString().Length != 18)
                return 0;
            return APP.DeleteByPagerId(paperId);
        }
        /// <summary>
        /// 删除单条回复
        /// </summary>
        /// <param name="postId"></param>
        /// <returns></returns>
        public int Delete(long postId)
        {
            if (postId == 0 || postId.ToString().Length != 18)
                return 0;
            return APP.Delete(postId);
        }

        /// <summary>
        /// 根据PaperId获取所有回复
        /// </summary>
        /// <param name="paperId"></param>
        /// <returns></returns>
        public List<PostInfo> GetAllPostByPaperId(long paperId)
        {
            if (paperId == 0 || paperId.ToString().Length != 18)
                return null;
            return APP.GetAllPostByPaperId(paperId);

        }
         /// <summary>
        /// 根据PaperId获取所有回复带用户的UserName和NickName
        /// </summary>
        /// <param name="paperId"></param>
        /// <returns></returns>
        public List<PostInfo> GetAllPostANDUserNameByPaperId(long paperId)
        {
             if (paperId == 0 || paperId.ToString().Length != 18)
                return null;
             return APP.GetAllPostANDUserNameByPaperId(paperId);
        }
        #endregion
    }
}
